package com.iflytek.controller;

import com.iflytek.common.Result;
import com.iflytek.dto.NoticeDTO;
import com.iflytek.dto.PageDTO;
import com.iflytek.service.NoticeService;
import com.iflytek.vo.NoticeVO;
import com.iflytek.vo.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author h_t
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/api/notice")
public class NoticeController {
    @Autowired
    public NoticeService noticeService;

    /**
     * 查询所有角色接口
     *
     * @param dto
     * @return
     */
    @ApiOperation("查询所有通知")
    @GetMapping("")
    public Result<List<NoticeVO>> findAll(NoticeDTO dto) {
        return noticeService.findAll(dto);
    }

    /**
     * 角色分页查询接口
     *
     * @param dto
     * @return
     */
    @ApiOperation("通知分页查询")
    @GetMapping("/page")
    public Result<PageVO<NoticeVO>> getPage(PageDTO<NoticeDTO> dto) {
        return noticeService.getPage(dto);
    }

    /**
     * 角色新增
     *
     * @param dto
     * @return
     */
    @ApiOperation("通知新增")
    @PostMapping("")
    public Result<Boolean> save(@RequestBody NoticeDTO dto) {
        return noticeService.saveNT(dto);
    }

    /**
     * 角色更新
     *
     * @param dto
     * @return
     */
    @ApiOperation("通知更新")
    @PutMapping("")
    public Result<Boolean> update(@RequestBody NoticeDTO dto) {
        return noticeService.updateNT(dto);
    }

    /**
     * 根据id查询角色信息
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id通知查询")
    @GetMapping("/findById/{id}")
    public Result<NoticeVO> findById(@PathVariable("id") Integer id) {
        return noticeService.findById(id);
    }


    /**
     * 根据id删除通知信息
     *
     * @param id
     * @return
     */
    @ApiOperation("通知删除")
    @DeleteMapping("{id}")
    public Result<Boolean> DeleteNotice(@PathVariable("id") Long id) {

        return noticeService.DeleteNotice(id);

    }

}